package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
//使用无参和有参构造器实例化Student对象
public class Test {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class cls = Class.forName("reflect.Student");
        Object obj = cls.newInstance();//无参构造器实例化对象
        System.out.println(obj);

        Constructor c = cls.getConstructor(String.class,int.class,char.class);
        Object obj1 = c.newInstance("张三",24,'男');//有参构造器实例化对象
        System.out.println(obj1);
    }
}
